package service;
/*
    date：
    topic：
    
*/

import entity.Companyinfo;
import myutil.DBUtil;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class CompanyinfoDao {

    public int getCount(String sql) {
        int count=0;
        Connection connection = DBUtil.getConn();
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            statement=connection.createStatement();
            resultSet=statement.executeQuery(sql);
            while(resultSet.next()) {
                count=resultSet.getInt(1);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close(connection, statement, resultSet);
        }
        return count;
    }

    public List<Companyinfo> getList(String sql){
        List<Companyinfo> list = new ArrayList<>();
        Connection connection = DBUtil.getConn();
        Statement statement = null;
        ResultSet resultSet = null;
        try {
            statement=connection.createStatement();
            resultSet=statement.executeQuery(sql);
            while(resultSet.next()) {
                Companyinfo companyinfo = new Companyinfo(resultSet.getString(1),resultSet.getString(2),resultSet.getString(3));
                list.add(companyinfo);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close(connection, statement, resultSet);
        }
        return list;
    }

}

